<template>
	<view class="body">
		<uni-nav-bar
		fixed="true"
		left-text="返回" 
		leftIcon="left"
		title="忘记密码" 
		height="130rpx"
		/>
		<view class="content">
			<view class="model w">
				<text class="iconfont icon-mobilephone-copy"></text>
				<input type="text" value="" placeholder="请输入手机号" v-model="mobile"/>
			</view>
			<view class="code w">
				<text class="iconfont icon-lock"></text>
				<input type="password" value="" placeholder="请输入验证码" v-model="code" />
				<button type="default" @click="getcode" :disabled="disabled">{{ codetip }}</button>
			</view>
			<view class="pass w">
				<text class="iconfont icon-lock"></text>
				<input type="password" value="" placeholder="请输入新密码" v-model="pass"/>
				<text class="iconfont icon-browse"></text>
			</view>
		</view>
		<button type="default" class="go" @click="getchangePassForget">下一步</button>
	</view>
</template>

<script>
	import {changePassForget,sendcode} from '../../api/user.js'
	export default{
		data(){
			return{
				mobile: '',
				code: '',
				pass: '',
				codetip: '获取验证码',
				disabled: false,
				time: 60,
				btnnum: 0,
			}
		},
		methods:{
			// 发送验证码
			async getcode() {
				if(this.mobile==''){
					uni.showToast({
						title:'手机号不能为空'
					})
				}else{
					const params = {
					mobile: this.mobile
				};
				let res = await sendcode(params);
				this.gettimer();
				console.log(res);
				}
			},
			gettimer() {
				this.time = 60;
				this.timer();
			},
			// 倒计时
			timer() {
				if (this.time > 0) {
					this.disabled = true;
					this.time--;
					this.codetip = this.time + '秒';
					setTimeout(this.timer, 1000);
				} else {
					this.time = 0;
					this.codetip = '发送验证码';
					this.disabled = false;
				}
			},
			async getchangePassForget(){
				if(this.mobile==''){
					uni.showToast({
						title:'账号不能为空'
					})
				}else if(this.code==''){
					uni.showToast({
						title:'验证码不能为空'
					})
				}
				else if(this.pass==''){
					uni.showToast({
						title:'密码不能为空'
					})
				}else{
				const params = {
					mobile: this.mobile,
					code:this.code,
					pass:this.pass
				};
				console.log(params)
				const res = await changePassForget(params)
				console.log(res)
				console.log(this.code)
				if(res.errCode==10000){
					uni.navigateTo({
					url:'/pages/login/login'
				})
				}
				
			}
			}
		}
	}
</script>

<style lang="less">
	@import '@/static/style/changePassForget.less';
</style>
